import os

from langchain import hub
from langchain.agents import create_tool_calling_agent, create_openai_tools_agent, create_openai_functions_agent, \
    AgentExecutor
from langchain_community.agent_toolkits.load_tools import load_tools
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI

os.environ['LANGCHAIN_TRACING_V2'] = 'true'
os.environ['LANGCHAIN_PROJECT'] = 'LLMDEMO'
os.environ['LANGCHAIN_API_KEY'] = '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'
os.environ['LANGSMITH_API_KEY'] = "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"
llm = ChatOpenAI(
    api_key="sk-a3f7718fb81f43b2915f0a6483b6661b",
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
    model="llama-4-scout-17b-16e-instruct",  # 此处以qwen-plus为例，您可按需更换模型名称。模型列表：https://help.aliyun.com/zh/model-studio/getting-started/models
    # other params...
)
from langsmith import Client
client = Client(api_key="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")
prompt = hub.pull("hwchase17/openai-functions-agent")
@tool
def weather() -> str:
    """今天的天气"""
    return "多云转晴"
#加载内置的tool
# tools = load_tools(["llm-math"], llm=llm)
tools = [weather]
agent = create_tool_calling_agent(llm=llm,tools=tools,prompt=prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
print(agent_executor.invoke({"input":"你好,今天天气怎么样"}))